home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / arc / fact127.zip / 4AR.BTM next >
Text File  |  1996-05-23  |  10KB  |  451 lines

  1. ::*────────────────────────────────────────────────────────────────────────┐
  2. ::* Simple 4DOS Archive Reader.  Allows you to read files within archives. │
  3. ::* Public Domain, by David Daniel Anderson.    Version 1.27, 23-May-1996  │
  4. ::* Comments welcome:  dda@panasia.com                                     │
  5. ::*                                                                        │
  6. ::* Run with just a question mark (?) to view basic help and information.  │
  7. ::*                                                                        │
  8. ::* Note:  Go to line number 33 to set your preferred file viewer.         │
  9. ::*────────────────────────────────────────────────────────────────────────┘
  10. iff "%1"=="" then
  11.   if exist *.* goto startbtm
  12.   if "%@findfirst[*.*,d]" ne "" goto startbtm
  13. else
  14.   if "%1"=="?" goto help
  15.   if exist %1 goto startbtm
  16.   if isdir %1 goto startbtm
  17.   if "%@findfirst[%1,d]" ne "" goto startbtm
  18. endiff
  19.  
  20. ::! If run in a totally empty directory, or
  21. ::! if run with an invalid first parameter, then show help.
  22. goto help
  23.  
  24. ::! NOTE: I unset my PROMPT and CDPATH in large BTM's to release some
  25. ::! precious environment space.  Do NOT unset COMSPEC or PATH!
  26. :startbtm
  27. setlocal
  28. unalias *
  29. set prompt=
  30. set cdpath=
  31.  
  32. ::! Change the following to whatever program you use to read files.
  33. set read=LIST
  34. iff %_env lt 300 then
  35.   cls
  36.   echo.
  37.   echo WARNING!
  38.   echo.
  39.   echo This batch file consumes 150 to 300 bytes of environment space.
  40.   echo You only have %_env bytes of environment space available now.
  41.   echo.
  42.   echo OPTION 1: Press "c" if you want to continue anyway.
  43.   echo.
  44.   echo OPTION 2: Press "r" to recurse (have the batch file call itself
  45.   echo   with a larger environment).  It will do this by calling another
  46.   echo   instance of: %comspec
  47.   echo.
  48.   echo OPTION 3: Press any other key to terminate the batch file.
  49.   echo   Note: If you choose this option, you can edit lines 24+ of the
  50.   echo   batch file to unset any unneeded variables.
  51.   echo.
  52.   inkey %%y
  53.   iff %@upper["%y"]=="C" then
  54.     set y=
  55.     goto continue
  56.   endiff
  57.   iff %@upper["%y"]=="R" then
  58.     set y=
  59.     %comspec //EnvFree=350 /c %0 %&
  60.   else
  61.     echo Quitting at your request.
  62.     quit
  63.   endiff
  64.   quit
  65. endiff
  66.  
  67. ::! Set unique temporary subdirectory name, and create it.
  68. :continue
  69. set tempdir=%@search[%@unique[%temp]]
  70. if "%tempdir"=="" goto error1
  71. del /q %tempdir
  72. md %tempdir
  73. attrib /dq +h %tempdir
  74.  
  75. ::! Set files to select.
  76. iff "%1"=="" then
  77.   set arcf=%_cwds%*.*
  78.   cdd %tempdir
  79. else
  80.   set newarc=%@full[%1]
  81.   cdd %tempdir
  82.  
  83. ::! If %1 refers to a directory, then use it.
  84.   iff NOT isdir %newarc then
  85.  
  86. ::! If %1 refers to one file, then immediately act on that one.
  87.     iff %@findfirst[%newarc]=%newarc then
  88.  
  89. ::! Set the primary file selection to all files in the same dir as %1
  90.       set arcf=%@path[%newarc]*.*
  91.       goto CheckExt
  92.     endiff
  93.  
  94. ::! Else preserve the ambiguous parameter.
  95.   endiff
  96.   set arcf=%newarc
  97. endiff
  98.  
  99. ::! Select an archive to process.
  100. ::! Pressing "Escape" will allow us to exit.
  101. :SelArc
  102. cls
  103. set newarc=
  104. *select /e /o:en set newarc=(%arcf)
  105. if %newarc.==. goto cleanup
  106.  
  107. ::! Reset archive selection menu.
  108. :ReSetArc
  109. iff isdir %newarc then
  110.   set arcf=%@full[%newarc]
  111.   goto SelArc
  112. endiff
  113.  
  114. ::! Check whether this file is an archive.
  115. ::! If it is, then set the necessary compressor parameters.
  116. ::! If not, then just view it.
  117. :CheckExt
  118. iff islabel %@ext[%@word[0,%newarc]] then
  119.   *unset /q aview aextr left width fs c l
  120.   gosub %@ext[%@word[0,%newarc]]
  121. else
  122.   %read %@word[0,%newarc]
  123.   goto Backout
  124. endiff
  125.  
  126. ::! Select a file to extract.
  127. set xfile=
  128. cls
  129. %aview %@word[0,%newarc] %c | set xfile=%@select[con,0,0,%_rows,%_columns,┤ Select a file: ├]
  130. cls
  131.  
  132. ::! If we pressed "Escape", back up one level.
  133. if "%xfile"=="" goto Backout
  134.  
  135. ::! Get an actual file name to extract.
  136. set xfile=%@trim[%@substr[%xfile,%left,%width]]
  137. if "%xfile"=="" goto Backout
  138.  
  139. ::! Change forward slashes to backward slashes.
  140. :BSlash
  141. set fs=%@index[%xfile,/]
  142. iff %fs ge 0 then
  143.   set xfile=%@substr[%xfile,0,%fs]\%@substr[%xfile,%@eval[%fs+ 1],255]
  144.   goto BSlash
  145. endiff
  146.  
  147. ::! Convert double spaces to single.
  148. :OneSpace
  149. set fs=%@index[%xfile,  ]
  150. iff %fs ge 0 then
  151.   set xfile=%@substr[%xfile,0,%fs]%@substr[%xfile,%@eval[%fs+ 1],255]
  152.   goto OneSpace
  153. endiff
  154.  
  155. ::! Convert space-dot to just dot.
  156. :SpaceDot
  157. set fs=%@index[%xfile, .]
  158. iff %fs ge 0 then
  159.   set xfile=%@substr[%xfile,0,%fs]%@substr[%xfile,%@eval[%fs+ 1],255]
  160.   goto SpaceDot
  161. endiff
  162.  
  163. ::! Replace the first remaining space with a period.
  164. :Periods
  165. set fs=%@index[%xfile, ]
  166. iff %fs ge 0 then
  167.   set xfile=%@substr[%xfile,0,%fs].%@substr[%xfile,%@eval[%fs+ 1],255]
  168.   REM goto Periods
  169. endiff
  170.  
  171. ::! Now extract the file, if it doesn't exist.
  172. cls
  173. iff "%all"=="y" then
  174.   if not exist %xfile %aextr %@word[0,%newarc] %l
  175.   unset /q all
  176. else
  177.   if not exist %xfile %aextr %@word[0,%newarc] %xfile %l
  178. endiff
  179. if %? ge 1 (beep^pause)
  180. *unset /q aview aextr left width fs c l
  181. cls
  182.  
  183. ::! Append new name to string of files being searched.
  184. set newarc=%_cwds%%xfile %newarc
  185. iff %_env lt 100 then
  186.   cls
  187.   echo.
  188.   echo You are running low on environment space!
  189.   echo If you go deeper into this archive, you may run into problems.
  190.   echo Environment left: %_env
  191.   echo.
  192.   set
  193.   echo.
  194.   pause
  195. endiff
  196. set xfile=
  197.  
  198. ::! Finally, go back to determine if this is an archive or not.
  199. goto CheckExt
  200.  
  201. ::! Back out of nested searching.
  202. :Backout
  203. set newarc=%@trim[%@substr[%newarc,%@eval[%@len[%@word[0,%newarc]]],255]]
  204. iff "%newarc"=="" then
  205.  
  206. ::! Make sure we are in the temp dir, and erase everything
  207. ::! before starting a new archive.
  208.  
  209.   cdd %tempdir
  210.   del /sxyz /q *.* >&>nul
  211.   goto SelArc
  212.  
  213. else
  214.   goto CheckExt
  215. endiff
  216.  
  217. ::! Sent here to remove temporary directory when we are done.
  218. :cleanup
  219. cdd %tempdir
  220. cd ..\
  221. iff isdir %tempdir then
  222.   del /sxyz /q %tempdir >&>nul
  223. endiff
  224. quit
  225.  
  226. :error1
  227. echo Your TEMP variable is set to a location which either does not exist
  228. echo or is a READ-ONLY drive.  You must fix it before running this batch
  229. echo file.
  230. echo.
  231. pause
  232. goto help
  233.  
  234. ::!##########################################################################
  235. ::!
  236. ::! The rest of the .BTM consists of definitions for various compressors.
  237. ::! Here is how to define them:
  238. ::!
  239. ::!   :???    Create a label with the compressor's file extension.
  240. ::!
  241. ::!   aview=  The command to view the archive contents.
  242. ::!   aextr=  The command to extract a file from the archive.
  243. ::!   left=   The number of characters from the beginning of the
  244. ::!           internal file names to the *left* edge of the screen.
  245. ::!   width=  The maximum width that the filenames may take up (usually 12).
  246. ::!   return  Since these are "gosubs", you MUST end with "return".
  247. ::!
  248. ::! Note: not all of these definitions handle subdirectories properly.
  249. ::!
  250. ::!##########################################################################
  251.  
  252. :acb
  253. set aview=acb l
  254. set aextr=acb r
  255. set left=33
  256. set width=40
  257. set all=y
  258. return
  259.  
  260. :ain
  261. set aview=ain l
  262. set aextr=ain e
  263. set left=0
  264. set width=12
  265. return
  266.  
  267. :arc
  268. set aview=pkunpak -v
  269. set aextr=pkunpak -e
  270. set left=0
  271. set width=12
  272. return
  273.  
  274. :arj
  275. set aview=arj l
  276. set aextr=arj e
  277. set left=0
  278. set width=12
  279. return
  280.  
  281. :dwc
  282. set aview=dwc v
  283. set aextr=dwc e
  284. set left=0
  285. set width=12
  286. return
  287.  
  288. :ha
  289. set aview=ha l
  290. set aextr=ha e
  291. set left=2
  292. set width=12
  293. return
  294.  
  295. :hap
  296. set aview=hap l
  297. set aextr=pah e
  298. set c=*.*
  299. set left=11
  300. set width=12
  301. return
  302.  
  303. :hpk
  304. set aview=hpack v -r
  305. set aextr=hpack x -r -dc
  306. set left=47
  307. set width=12
  308. return
  309.  
  310. :hyp
  311. set aview=hyper -v
  312. set aextr=hyper -xo -p
  313. set left=49
  314. set width=29
  315. return
  316.  
  317. :jrc
  318. set aview=jrcl
  319. set aextr=jrce
  320. set left=0
  321. set width=12
  322. return
  323.  
  324. :lib
  325. set aview=codec -v
  326. set aextr=codec -d
  327. set c=* -m -q
  328. set l=-m
  329. set left=0
  330. set width=33
  331. return
  332.  
  333. :lim
  334. set aview=limit l
  335. set aextr=limit e
  336. set left=2
  337. set width=12
  338. return
  339.  
  340. :lzh
  341. set aview=lha v
  342. set aextr=lha x
  343. set left=0
  344. set width=64
  345. return
  346.  
  347. :lzs
  348. set aview=larc l
  349. set aextr=larc e /x /o
  350. set left=0
  351. set width=64
  352. return
  353.  
  354. :pak
  355. set aview=pak v
  356. set aextr=pak e
  357. set left=0
  358. set width=12
  359. return
  360.  
  361. :paq
  362. set aview=unpaq -v
  363. set aextr=unpaq -x -d
  364. set left=29
  365. set width=50
  366. set all=y
  367. return
  368.  
  369. :rar
  370. set aview=rar v -std -bw
  371. set aextr=rar x -std -bw
  372. set left=1
  373. set width=40
  374. return
  375.  
  376. :sar
  377. set aview=sar l
  378. set aextr=sar e
  379. set left=0
  380. set width=12
  381. return
  382.  
  383. :sqz
  384. set aview=sqz l
  385. set aextr=sqz e
  386. set left=2
  387. set width=12
  388. return
  389.  
  390. :uc2
  391. set aview=uc vs
  392. set aextr=uc esf
  393. set left=0
  394. set width=12
  395. return
  396.  
  397. :x
  398. set aview=x1 l
  399. set aextr=x1 xy
  400. set left=0
  401. set width=21
  402. return
  403.  
  404. :yc
  405. set aview=yac l
  406. set aextr=yac e
  407. set left=41
  408. set width=12
  409. return
  410.  
  411. :zip
  412. set aview=pkzip -vb
  413. set aextr=pkunzip -d
  414. set left=46
  415. set width=29
  416. return
  417.  
  418. :zoo
  419. set aview=zoo -list
  420. set aextr=zoo -extract
  421. set left=49
  422. set width=12
  423. return
  424.  
  425. :help
  426. echo.
  427. echo  4DOS batch file:  %0
  428. echo  Public Domain, by David Daniel Anderson.    Version 1.27, 23-May-1996
  429. echo.
  430. echo  Usage: %0 [archive(s)]
  431. echo.
  432. TEXT
  433.  This 4DOS batch file allows you to read files within archives.
  434.  
  435.  In order to use this, you will need the archivers themselves,
  436.  and a file viewer (or use 4DOS's LIST command -- see line #33).
  437.  
  438.  This batch file comes preconfigured for the archivers that use
  439.  the following extensions:
  440.  
  441.      ACB  AIN  ARC  ARJ  DWC  HA   HAP  HPK  HYP  JRC
  442.      LIB  LIM  LZH  LZS  PAK  PAQ  RAR  SAR  SQZ  UC2
  443.      X    YC   ZIP  ZOO
  444.  
  445.  Adding more definitions, and editing these, are both simple tasks.
  446.  See the comments in the batch file, starting at line number 234.
  447.  
  448.  Note: not all archivers are 100% compatible with the methods I use.
  449. ENDTEXT
  450. quit
  451.